package com.zqj.spring_mybatis.userInfo.service.impl;

import com.zqj.spring_mybatis.base.utils.IdWorker;
import com.zqj.spring_mybatis.userInfo.mapper.UserInfoMapper;
import com.zqj.spring_mybatis.userInfo.pojo.UserInfo;
import com.zqj.spring_mybatis.userInfo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserInfoServiceImpl implements UserInfoService{

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Value("${IdWorker.workerId}")
    private Integer workerId;
    @Value("${IdWorker.datacenterId}")
    private Integer datacenterId;



    @Override
    public List<UserInfo> getUser() throws Exception {
        return userInfoMapper.getUser();
    }

    @Override
    public void deleteUser(int id) throws Exception {
        userInfoMapper.deleteUser(id);

    }


    @Override
    public void addUser(UserInfo user) throws Exception {
        IdWorker idWorker = new IdWorker(workerId,datacenterId);
        Long autoId = idWorker.nextId();

        user.setId(autoId);
        userInfoMapper.addUser(user);
    }
}
